package tgc.edu.tms.web.controller;

import java.util.HashSet;

import org.abyss.data.specifications.Rule;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import tgc.edu.tms.custom.CommonController;
import tgc.edu.tms.entity.Location;
import tgc.edu.tms.web.form.LocationForm;

@Controller
@RequestMapping(value="/dictionary/location")
public class LocationController extends CommonController<Location, Integer, LocationForm>{
	
	@Override
	public Specification<Location> buildSpec(LocationForm form) {
		HashSet<Rule> rules=new HashSet<>();
		String search = form.getSearch();
		if(StringUtils.hasText(search)){
			HashSet<Rule> rules2=new HashSet<>();
			rules2.add(Rule.property("name").contain(search));
			rules.add(Rule.or(rules2));
		}
		return Rule.and(rules).toSpecification();
		
	}

}
